cmake_minimum_required (VERSION 3.8.2)
project (ffead-cpp-7.0)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckSymbolExists)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_SKIP_BUILD_RPATH true)
if(POLICY CMP0068)
  cmake_policy(SET CMP0068 NEW)
endif()

option(DEBUG "Generate with debug options" OFF)
option(MOD_MEMORY "Enable Memory Cache module" ON)
option(MOD_MEMCACHED "Enable Memcached Cache module" OFF)
option(MOD_REDIS "Enable Redis Cache module" OFF)
option(MOD_SDORM_SQL "Enable SQL Sdorm module" ON)
option(MOD_SDORM_MONGO "Enable Mongo Sdorm module" OFF)
option(MOD_SDORM_SCYLLA "Enable Scylladb Sdorm module" OFF)
option(MOD_SOLR "Enable SOLR Search module" OFF)
option(MOD_ELASTIC "Enable Elasticsearch Search module" OFF)
option(MOD_SER_BIN "Enable Binary Serialization module" OFF)
option(MOD_JOBS "Enable Jobs module" ON)
option(MOD_APACHE "Enable Apache module" OFF)
option(MOD_NGINX "Enable Nginx module" OFF)
option(SRV_ALL "Build All inbuilt HTTP Server Engines" OFF)
option(SRV_EMB "Embedded Http Server Engine" ON)
option(SRV_CINATRA "Cinatra Http Server Engine" OFF)
option(SRV_LITHIUM "Lithium Http Server Engine" OFF)
option(SRV_DROGON "Drogon Http Server Engine" OFF)
option(SRV_NGHTTP2 "Nghttp2 Http Server Engine" OFF)
#option(SRV_MONGOLS "Mongols Http Server Engine" OFF)
option(SRV_UVCPP "Uv-Cpp Http Server Engine" OFF)
option(SRV_CPPSRV "CppServer Http Server Engine" OFF)
option(BUILD_SHARED_LIBS "Build with shared libraries" ON)
option(WITH_RAPIDJSON "Use rapidjson for json handling" ON)
option(WITH_PUGIXML "Use pugixml for xml handling" ON)
option(WITH_PICOEV "Enable picoev engine" OFF)

option(WITH_SELECT "Force SELECT support" OFF)
option(WITH_POLL "Force POLL support" OFF)
option(WITH_DEVPOLL "Force DEVPOLL support" OFF)
option(WITH_IOURING "Force IOURING support" OFF)

#set(BUILD_STATIC_LIBS OFF)
#set(BUILD_SHARED_LIBS ON)
set(LIB_EXT "${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(NOT BUILD_SHARED_LIBS)
	set(BUILD_STATIC_LIBS ON)
	set(LIB_EXT "${CMAKE_STATIC_LIBRARY_SUFFIX}")
	#set(LNK_BOP "-Wl,--whole-archive")
	#set(LNK_AOP "-Wl,--no-whole-archive")
else()
	set(BUILD_STATIC_LIBS OFF)
	set(LIB_EXT "${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()

if(NOT CINATRA_INCLUDES)
	set(CINATRA_INCLUDES "/cinatra/include")
endif()
#if(NOT SSL_INC_DIR)
#	set(SSL_INC_DIR "/usr/local/opt/openssl/include")
#endif()
#if(NOT SSL_LIB)
#	set(SSL_LIB "/usr/local/opt/openssl/lib/libssl.dylib")
#endif()
#if(NOT CRYPTO_LIB)
#	set(CRYPTO_LIB "/usr/local/opt/openssl/lib/libcrypto.dylib")
#endif()

set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(CMAKE_VERBOSE_MAKEFILE off)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_INC_PATH)
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_INC_PATH}/include")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${CMAKE_INC_PATH}/include")
else()
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include")
	if(APPLE)
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/include")
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/include")
	endif()
endif()
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})

if(EMSCRIPTEN)
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_ZLIB=1 -s USE_PTHREADS=1")
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_ZLIB=1 -s USE_PTHREADS=1")
endif()

string( TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC )
if (CMAKE_BUILD_TYPE_LC STREQUAL "debug")
	set(DEBUG ON)
endif()

if(DEBUG)
	set(CMAKE_BUILD_TYPE DEBUG)
	set(TO_REPLACE_DEBUG "set(CMAKE_BUILD_TYPE DEBUG)")
	#if (APPLE)
	#	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
	#endif()
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_DEBUG")
else()
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif(DEBUG)
if(CMAKE_INC_PATH)
	include_directories("${CMAKE_INC_PATH}/include" "${CMAKE_SOURCE_DIR}/modules/common" "${CMAKE_SOURCE_DIR}/modules/cache" "${CMAKE_SOURCE_DIR}/modules/client-util")
else()
	include_directories("/usr/local/include" "${CMAKE_SOURCE_DIR}/modules/common" "${CMAKE_SOURCE_DIR}/modules/cache" "${CMAKE_SOURCE_DIR}/modules/client-util")
endif()

include_directories("${CMAKE_SOURCE_DIR}/modules/http" "${CMAKE_SOURCE_DIR}/modules/http/http11" "${CMAKE_SOURCE_DIR}/modules/http/http20" "${CMAKE_SOURCE_DIR}/modules/ioc")
include_directories("${CMAKE_SOURCE_DIR}/modules/jobs" "${CMAKE_SOURCE_DIR}/modules/reflection" "${CMAKE_SOURCE_DIR}/modules/sdorm" "${CMAKE_SOURCE_DIR}/modules/search")
include_directories("${CMAKE_SOURCE_DIR}/modules/serialization" "${CMAKE_SOURCE_DIR}/modules/serialization/xml" "${CMAKE_SOURCE_DIR}/modules/serialization/json")
include_directories("${CMAKE_SOURCE_DIR}/modules/server-util" "${CMAKE_SOURCE_DIR}/modules/ssl" "${CMAKE_SOURCE_DIR}/modules/threads")

include_directories("${CMAKE_SOURCE_DIR}/modules/search")
if(MOD_SOLR)
	set(HAVE_SOLR "")
	include_directories("${CMAKE_SOURCE_DIR}/modules/search/solr")
endif()
if(MOD_ELASTIC)
	CHECK_INCLUDE_FILE_CXX("elasticlient/client.h" HAVE_ELASTIC)
	if(HAVE_ELASTIC)
		include_directories("${CMAKE_SOURCE_DIR}/modules/search/elasticsearch")
		FIND_LIBRARY(HAVE_ELASTICLIB elasticlient)
		if(NOT HAVE_ELASTICLIB)
			message(FATAL_ERROR "elasticlient library not found")
		endif()
		CHECK_INCLUDE_FILE_CXX("cpr/response.h" HAVE_CPR)
		if(NOT HAVE_CPR)
			message(FATAL_ERROR "libcpr includes not found")
		endif()
		FIND_LIBRARY(HAVE_CPRLIB cpr)
		if(NOT HAVE_CPRLIB)
			message(FATAL_ERROR "cpr library not found")
		endif()
	endif()
endif()

if(CMAKE_INC_PATH)
	include_directories("${CMAKE_SOURCE_DIR}/framework" "${CMAKE_INC_PATH}/include")
else()
	include_directories("${CMAKE_SOURCE_DIR}/framework")
endif()

find_package(Threads)

# CMake does not distinguish Linux from other Unices.
STRING (REGEX MATCH ".*Linux.*" PROJECT_OS_LINUX ${CMAKE_SYSTEM_NAME})
# Nor *BSD
STRING (REGEX MATCH ".*BSD.*" PROJECT_OS_BSD ${CMAKE_SYSTEM_NAME})
# Or Solaris. I'm seeing a trend, here
STRING (REGEX MATCH ".*SunOS.*" PROJECT_OS_SOLARIS ${CMAKE_SYSTEM_NAME})

if(NOT PROJECT_OS_SOLARIS)
    if(APPLE)
        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,dynamic_lookup")
    else()
        set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
    endif()
endif()

set(HAVE_WINREGEX "")

if(APPLE)
	set(OS_DARWIN 1)
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${SSL_INC_DIR}")
	set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/opt/homebrew/include")
	include_directories("/usr/local/include" "/opt/homebrew/include")
elseif(MINGW)
	set(OS_MINGW 1)
	set(USE_WIN_IOCP 1)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__USE_MINGW_ANSI_STDIO=1")
    add_compile_options(-Wa,-mbig-obj)
    if(CMAKE_INC_PATH)
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include")
	else()
		set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/wepoll")
	set(HAVE_WSOCK32 wsock32)
	set(HAVE_WS232 ws2_32)
	if (WIN32 AND CMAKE_HOST_WIN32)
		set(HAVE_WINREGEX regex)
	endif()
	CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLINC)
	if(NOT HAVE_DLINC)
		message(FATAL_ERROR "dlfcn includes not found")
	endif()
	FIND_LIBRARY(HAVE_DLLIB dl)
	if(NOT HAVE_DLLIB)
		message(FATAL_ERROR "dl library not found")
	endif()
elseif(CYGWIN)
	set(CYGWIN 1)
	add_compile_options(-Wa,-mbig-obj)
	if(CMAKE_INC_PATH)
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include")
	else()
		set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
	endif()
elseif(ANDROID)
	set(OS_ANDROID 1)
    if(CMAKE_INC_PATH)
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include")
	else()
		set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
	endif()
	set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
elseif(UNIX)
	IF (PROJECT_OS_BSD)
		set(OS_BSD 1)
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/v6/lib")
    ELSEIF (PROJECT_OS_SOLARIS)
    	set(OS_SOLARIS 1)
    	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthreads")
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lsocket -lnsl")
    ELSE()
    	set(OS_LINUX 1)
    ENDIF()
    if(CMAKE_INC_PATH)
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include")
	else()
		set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
	endif()
endif()

if(CMAKE_INC_PATH)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_INC_PATH}/lib")
	set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${CMAKE_INC_PATH}/lib")
else()
	if(APPLE)
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib -L/opt/homebrew/lib")
		set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/lib" "/opt/homebrew/lib")
	else()
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
		set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/usr/local/lib")
	endif()
endif()

set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(accept4	"sys/socket.h"	HAVE_ACCEPT4)

CHECK_INCLUDE_FILE("sys/sysinfo.h" HAVE_SYSINFO)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <netinet/tcp.h>
	int main() { return TCP_QUICKACK; }"
HAVE_TCP_QUICKACK)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <netinet/tcp.h>
	int main() { return TCP_DEFER_ACCEPT; }"
HAVE_TCP_DEFER_ACCEPT)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <netinet/tcp.h>
	int main() { return TCP_FASTOPEN; }"
HAVE_TCP_FASTOPEN)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	int main() { return SO_REUSEPORT; }"
HAVE_SO_REUSEPORT)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	int main() { return SO_REUSEADDR; }"
HAVE_SO_REUSEADDR)

include(CheckCSourceCompiles)
CHECK_C_SOURCE_COMPILES("
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <netinet/tcp.h>
	#include <linux/bpf.h>
	#include <linux/filter.h>
	#include <sys/sysinfo.h>
	int main() { return SO_ATTACH_REUSEPORT_CBPF; }"
HAVE_SO_ATTACH_REUSEPORT_CBPF)

if(EMSCRIPTEN)
	set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
	set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
	set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
	set(HAVE_CRYPTOLIB "")
	set(HAVE_CURLLIB "")
	set(HAVE_SSLLIB "")
	set(LIB_EXT "${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()

if(WITH_RAPIDJSON)
	CHECK_INCLUDE_FILE_CXX("rapidjson/document.h" HAVE_RAPID_JSON)
endif()
if(WITH_PUGIXML)
	CHECK_INCLUDE_FILE_CXX("pugixml.hpp" HAVE_PUGI_XML)
	if(HAVE_PUGI_XML)
		FIND_LIBRARY(HAVE_PUGI_XML_LIB NAMES pugixml HINTS "/usr/local/lib")
		if(NOT HAVE_PUGI_XML_LIB)
			message(FATAL_ERROR "pugixml library not found")
		endif()
	endif()
endif()

if(NOT MINGW AND NOT CYGWIN)
	CHECK_INCLUDE_FILE("regex.h" HAVE_REGEX)
endif()

if(NOT HAVE_REGEX)
	CHECK_INCLUDE_FILE("onigposix.h" HAVE_ONIG_REGEX)
	if(NOT HAVE_ONIG_REGEX)
		message(FATAL_ERROR "oniguruma includes not found")
	endif()
	if(EMSCRIPTEN)
		FIND_LIBRARY(HAVE_ONIG_REGEX_LIB NAMES onig HINTS "/usr/local/lib")
	else()
		FIND_LIBRARY(HAVE_ONIG_REGEX_LIB onig)
	endif()
	if(NOT HAVE_ONIG_REGEX_LIB)
		message(FATAL_ERROR "oniguruma library not found")
	endif()
endif()

FIND_LIBRARY(HAVE_CURLLIB curl)
#if(NOT HAVE_CURLLIB)
#	message(FATAL_ERROR "curl library not found")
#endif()

if(EMSCRIPTEN)
	#FIND_LIBRARY(HAVE_ZLIB NAMES z HINTS "/usr/local/lib")
	set(HAVE_ZLIB "")
else()
	FIND_LIBRARY(HAVE_ZLIB z)
endif()

if(NOT EMSCRIPTEN)
	if(NOT HAVE_ZLIB)
		message(FATAL_ERROR "z library not found")
	endif()
endif()

CHECK_INCLUDE_FILE("openssl/ssl.h" HAVE_SSLINC)
if(HAVE_SSLINC)
	include_directories("${CMAKE_SOURCE_DIR}/modules/client-util/ssl")
endif()
#if(NOT HAVE_SSLINC)
#	message(FATAL_ERROR "openssl includes not found")
#endif()
#if (APPLE)
#	set(HAVE_SSLLIB ${SSL_LIB})
#	set(HAVE_CRYPTOLIB ${CRYPTO_LIB})
#else()
	if(NOT BUILD_SHARED_LIBS)
		FIND_LIBRARY(HAVE_SSLLIB NAMES libssl.a ssl)
	else()
		FIND_LIBRARY(HAVE_SSLLIB ssl)
	endif()
#	if(NOT HAVE_SSLLIB)
#		message(FATAL_ERROR "ssl library not found")
#	endif()
	if(NOT BUILD_SHARED_LIBS)
		FIND_LIBRARY(HAVE_CRYPTOLIB NAMES libcrypto.a crypto)
		if(NOT EMSCRIPTEN)
			FIND_LIBRARY(HAVE_DLLIB NAMES libdl.a dl)
		else()
			set(HAVE_DLLIB "")
		endif()
	else()
		FIND_LIBRARY(HAVE_CRYPTOLIB crypto)
		if(NOT HAVE_DLLIB)
			set(HAVE_DLLIB "")
		endif()
	endif()
#	if(NOT HAVE_CRYPTOLIB)
#		message(FATAL_ERROR "crypto library not found")
#	endif()
#endif()

#FIND_LIBRARY(HAVE_TBBLIB tbb)
#if(NOT HAVE_TBBLIB)
#	message(FATAL_ERROR "tbb library not found")
#endif()
#CHECK_INCLUDE_FILE_CXX("tbb/concurrent_hash_map.h" HAVE_TBBINC)
#if(NOT HAVE_TBBINC)
#	message(FATAL_ERROR "tbb includes not found")
#endif()

CHECK_INCLUDE_FILE_CXX("libcuckoo/cuckoohash_map.hh" HAVE_CKOHMINC)
if(NOT HAVE_CKOHMINC)
	message(FATAL_ERROR "libcuckoo includes not found")
endif()

if(EMSCRIPTEN)
	FIND_LIBRARY(HAVE_UUIDLIB NAMES uuid HINTS "/usr/local/lib")
else()
	FIND_LIBRARY(HAVE_UUIDLIB uuid)
endif()
if(NOT HAVE_UUIDLIB)
	FIND_LIBRARY(HAVE_UUIDLIB ossp-uuid)
	if(NOT HAVE_UUIDLIB)
		message(FATAL_ERROR "uuid library not found")
	endif()
endif()

CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFOINC)

if(WITH_PICOEV)
	set(USE_PICOEV "1")
endif()

if(WITH_IOURING)
	execute_process(COMMAND uname -r OUTPUT_VARIABLE UNAME_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE)
	message(-- " Kernel version: " ${UNAME_RESULT})
	string(REGEX MATCH "[0-9]+.[0-9]+" LINUX_KERNEL_VERSION ${UNAME_RESULT})
	message(-- " Linux version: " ${LINUX_KERNEL_VERSION})
	
	CHECK_INCLUDE_FILE("liburing.h" USE_IO_URING)
	if (LINUX_KERNEL_VERSION VERSION_LESS 5.6)
		set(LIBURING_KERNEL 0)
		message(FATAL_ERROR "Linux kernel version is < 5.6")
	else()
		CHECK_INCLUDE_FILE("liburing.h" USE_IO_URING)
		FIND_LIBRARY(HAVE_LIBURING uring)
		if(NOT HAVE_LIBURING)
			message(FATAL_ERROR "uring library not found")
		endif()
	endif()
	unset(USE_PICOEV)
elseif(WITH_SELECT)
	CHECK_INCLUDE_FILE("sys/select.h" USE_SELECT)
	if(NOT USE_SELECT)
		message(FATAL_ERROR "sys/select.h not found")
	endif()
elseif(WITH_POLL)
	CHECK_INCLUDE_FILE("sys/poll.h" USE_POLL)
	if(NOT USE_POLL)
		message(FATAL_ERROR "sys/poll.h not found")
	endif()
elseif(USE_DEVPOLL)
	CHECK_INCLUDE_FILE("sys/devpoll.h" USE_DEVPOLL)
	if(NOT USE_DEVPOLL)
		message(FATAL_ERROR "sys/devpoll.h not found")
	endif()
elseif(NOT USE_WIN_IOCP)
	CHECK_INCLUDE_FILE("sys/epoll.h" USE_EPOLL)
	if(NOT USE_EPOLL)
		CHECK_INCLUDE_FILE("sys/event.h" USE_KQUEUE)
		if(NOT USE_KQUEUE)
			CHECK_INCLUDE_FILE("port.h" USE_EVPORT)
			if(NOT USE_EVPORT)
				CHECK_INCLUDE_FILE("sys/devpoll.h" USE_DEVPOLL)
				if(NOT USE_DEVPOLL)
					CHECK_INCLUDE_FILE("sys/poll.h" USE_POLL)
					if(NOT USE_POLL)
						CHECK_INCLUDE_FILE("sys/select.h" USE_SELECT)
					endif()
				endif()
			endif()
		endif()
	endif()
endif()

if(MOD_MEMORY)
	set(INC_MEMORYCACHE 1)
	include_directories("${CMAKE_SOURCE_DIR}/modules/cache/memory")
endif(MOD_MEMORY)
if(MOD_REDIS)
	set(INC_REDISCACHE 1)
	CHECK_INCLUDE_FILE("hiredis/hiredis.h" HAVE_REDISINC)
	FIND_LIBRARY(HAVE_REDISLIB hiredis)
	if(NOT HAVE_REDISLIB)
		message(FATAL_ERROR "hiredis library not found")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/cache/redis")
	CHECK_INCLUDE_FILE_CXX("sw/redis++/redis++.h" HAVE_REDIS_CLUSTERINC)
	if(HAVE_REDIS_CLUSTERINC)
		FIND_LIBRARY(HAVE_REDIS_CLUSTERLIB redis++)
		if(NOT HAVE_REDIS_CLUSTERLIB)
			message(FATAL_ERROR "redis++ library not found")
		endif()
	endif()
endif(MOD_REDIS)
if(MOD_MEMCACHED)
	set(INC_MEMCACHED 1)
	CHECK_INCLUDE_FILE("libmemcached/memcached.h" HAVE_MEMCACHEDINC)
	FIND_LIBRARY(HAVE_MEMCACHEDLIB memcached)
	if(NOT HAVE_MEMCACHEDLIB)
		message(FATAL_ERROR "memcached library not found")
	endif()
	FIND_LIBRARY(HAVE_MEMCACHEDUTILLIB memcachedutil)
	if(NOT HAVE_MEMCACHEDUTILLIB)
		message(FATAL_ERROR "memcachedutil library not found")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/cache/memcached")
endif(MOD_MEMCACHED)

if(MOD_SDORM_SQL)
	set(INC_SDORM 1)
	set(INC_SDORM_SQL 1)
	IF (PROJECT_OS_BSD)
		CHECK_INCLUDE_FILE("uuid.h" HAVE_BSDUUIDINC)
		if(NOT HAVE_BSDUUIDINC)
			CHECK_INCLUDE_FILE("uuid/uuid.h" HAVE_UUIDINC)
			if(NOT HAVE_UUIDINC)
				message(FATAL_ERROR "uuid includes not found")
			endif()
		endif()
	else()
		CHECK_INCLUDE_FILE("uuid/uuid.h" HAVE_UUIDINC)
		if(NOT HAVE_UUIDINC)
			CHECK_INCLUDE_FILE("ossp/uuid.h" HAVE_OSSPUUIDINC)
			if(NOT HAVE_OSSPUUIDINC)
				CHECK_INCLUDE_FILE("uuid.h" HAVE_OSSPUUIDINC_2)
				if(NOT HAVE_OSSPUUIDINC_2)
					message(FATAL_ERROR "uuid includes not found")
				endif()
			endif()
		endif()
	endif()
	if(CMAKE_INC_PATH)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${CMAKE_INC_PATH}/include/postgresql -I${CMAKE_INC_PATH}/include/pgsql")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_INC_PATH}/include/postgresql -I${CMAKE_INC_PATH}/include/pgsql")
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include" "${CMAKE_INC_PATH}/include/postgresql" "${CMAKE_INC_PATH}/include/pgsql")
		include_directories("${CMAKE_INC_PATH}/include/postgresql" "${CMAKE_INC_PATH}/include/pgsql")
		if(MINGW)
			set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include/unixodbc")
			include_directories("${CMAKE_INC_PATH}/include/unixodbc")
		endif()
	else()
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include/postgresql -I/usr/include/pgsql -I/usr/local/include/postgresql -I/usr/local/include/pgsql")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/postgresql -I/usr/include/pgsql -I/usr/local/include/postgresql -I/usr/local/include/pgsql")
		set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include/postgresql" "/usr/include/pgsql" "/usr/local/include/postgresql" "/usr/local/include/pgsql")
		include_directories("/usr/include/postgresql" "/usr/include/pgsql" "/usr/local/include/postgresql" "/usr/local/include/pgsql")
		if(MINGW)
			set(CMAKE_REQUIRED_INCLUDES "/usr/include/unixodbc")
			include_directories("/usr/include/unixodbc")
		elseif(APPLE)
			set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/include/postgresql -I/opt/homebrew/include/pgsql -I/opt/homebrew/opt/libpq/include")
			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/include/postgresql -I/opt/homebrew/include/pgsql -I/opt/homebrew/opt/libpq/include")
			set(CMAKE_REQUIRED_INCLUDES "/opt/homebrew/include/postgresql" "/opt/homebrew/include/pgsql" "/opt/homebrew/opt/libpq/include")
			set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "/opt/homebrew/opt/libpq/lib")
			include_directories("/opt/homebrew/include/postgresql" "/opt/homebrew/include/pgsql" "/opt/homebrew/opt/libpq/include")
			link_directories("/opt/homebrew/lib" "/opt/homebrew/opt/libpq/lib")
		endif()
	endif()
	CHECK_INCLUDE_FILE("sql.h" HAVE_SQLINC)
	if(NOT HAVE_SQLINC)
		message(FATAL_ERROR "odbc includes not found")
	endif()
	FIND_LIBRARY(HAVE_ODBCLIB odbc)
	if(NOT HAVE_ODBCLIB)
		message(FATAL_ERROR "odbc library not found")
	endif()
	CHECK_INCLUDE_FILE("libpq-fe.h" HAVE_PQHDR)
	FIND_LIBRARY(HAVE_LIBPQ pq)
	if(NOT HAVE_LIBPQ)
		set(HAVE_LIBPQ "")
	else()
		if(POLICY CMP0075)
		  cmake_policy(SET CMP0075 NEW)
		endif()
		set(CMAKE_REQUIRED_LIBRARIES "pq")
		check_symbol_exists(PQenterBatchMode "libpq-fe.h" HAVE_LIBPQ_BATCH)
		check_symbol_exists(PQenterPipelineMode "libpq-fe.h" HAVE_LIBPQ_PIPELINE)
		set(CMAKE_REQUIRED_LIBRARIES "")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/sdorm/sql" "${CMAKE_SOURCE_DIR}/modules/sdorm/sql/libpq")
else()
	set(HAVE_LIBPQ "")
endif(MOD_SDORM_SQL)
if(MOD_SDORM_MONGO)
	set(INC_SDORM 1)
	set(INC_SDORM_MONGO 1)
	IF (PROJECT_OS_BSD)
		CHECK_INCLUDE_FILE("uuid.h" HAVE_BSDUUIDINC)
		if(NOT HAVE_BSDUUIDINC)
			CHECK_INCLUDE_FILE("uuid/uuid.h" HAVE_UUIDINC)
			if(NOT HAVE_UUIDINC)
				message(FATAL_ERROR "uuid includes not found")
			endif()
		endif()
	else()
		CHECK_INCLUDE_FILE("uuid/uuid.h" HAVE_UUIDINC)
		if(NOT HAVE_UUIDINC)
			CHECK_INCLUDE_FILE("ossp/uuid.h" HAVE_OSSPUUIDINC)
			if(NOT HAVE_OSSPUUIDINC)
				CHECK_INCLUDE_FILE("uuid.h" HAVE_OSSPUUIDINC_2)
				if(NOT HAVE_OSSPUUIDINC_2)
					message(FATAL_ERROR "uuid includes not found")
				endif()
			endif()
		endif()
	endif()
	if(CMAKE_INC_PATH)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${CMAKE_INC_PATH}/include/libmongoc-1.0 -I${CMAKE_INC_PATH}/include/libbson-1.0")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_INC_PATH}/include/libmongoc-1.0 -I${CMAKE_INC_PATH}/include/libbson-1.0")
		set(CMAKE_REQUIRED_INCLUDES "${CMAKE_INC_PATH}/include/libmongoc-1.0" "${CMAKE_INC_PATH}/include/libbson-1.0" )
		include_directories("${CMAKE_INC_PATH}/include/libmongoc-1.0" "${CMAKE_INC_PATH}/include/libbson-1.0")
	else()
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0")
		set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/include/libmongoc-1.0 -I/usr/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 -I/usr/local/include/libbson-1.0")
		set(CMAKE_REQUIRED_INCLUDES "/usr/include/libmongoc-1.0" "/usr/include/libbson-1.0" "/usr/local/include/libmongoc-1.0" "/usr/local/include/libbson-1.0")
		include_directories("/usr/include/libmongoc-1.0" "/usr/include/libbson-1.0" "/usr/local/include/libmongoc-1.0" "/usr/local/include/libbson-1.0")
		if(APPLE)
			set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/include/libmongoc-1.0 -I/opt/homebrew/include/libbson-1.0")
			set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/include/libmongoc-1.0 -I/opt/homebrew/include/libbson-1.0")
			set(CMAKE_REQUIRED_INCLUDES "/opt/homebrew/include/libmongoc-1.0" "/opt/homebrew/include/libbson-1.0")
			include_directories("/opt/homebrew/include/libmongoc-1.0" "/opt/homebrew/include/libbson-1.0")
		endif()
	endif()
	CHECK_INCLUDE_FILE("mongoc.h" HAVE_MONGOINC)
	if(NOT HAVE_MONGOINC)
		message(FATAL_ERROR "mongoc includes not found")
	endif()
	FIND_LIBRARY(HAVE_MONGOCLIB mongoc-1.0)
	if(NOT HAVE_MONGOCLIB)
		message(FATAL_ERROR "mongoc-1.0 library not found")
	endif()
	CHECK_INCLUDE_FILE("bson.h" HAVE_BSONINC)
	if(NOT HAVE_BSONINC)
		message(FATAL_ERROR "bson includes not found")
	endif()
	FIND_LIBRARY(HAVE_BSONLIB bson-1.0)
	if(NOT HAVE_BSONLIB)
		message(FATAL_ERROR "bson-1.0 library not found")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/sdorm/mongo" "${CMAKE_SOURCE_DIR}/modules/sdorm/mongo/raw")
endif(MOD_SDORM_MONGO)
if(MOD_SDORM_SCYLLA)
	set(CMAKE_REQUIRED_INCLUDES "/usr/local/include")
	CHECK_INCLUDE_FILE("cassandra.h" HAVE_SCYLLAINC)
	if(NOT HAVE_SCYLLAINC)
		message(FATAL_ERROR "cassandra includes not found")
	endif()
	FIND_LIBRARY(HAVE_SCYLLALIB scylla-cpp-driver)
	if(NOT HAVE_SCYLLALIB)
		message(FATAL_ERROR "scylla-cpp-driver library not found")
	endif()
	include_directories("${CMAKE_SOURCE_DIR}/modules/sdorm/scylla/raw")
endif(MOD_SDORM_SCYLLA)
if(MOD_SER_BIN)
	set(INC_BINSER 1)
	include_directories("${CMAKE_SOURCE_DIR}/modules/serialization/binary")
endif(MOD_SER_BIN)
if(MOD_JOBS)
	set(INC_JOBS 1)
	include_directories("${CMAKE_SOURCE_DIR}/modules/jobs")
endif(MOD_JOBS)

set(CMAKE_CXX_FLAGS_NGX "${CMAKE_CXX_FLAGS}")
if(DEBUG)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
else()
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
endif()

CHECK_INCLUDE_FILE("sys/sendfile.h" IS_SENDFILE)

set(TO_REPLACE_CPPFLAGS ${CMAKE_CXX_FLAGS})
set(TO_REPLACE_LDFLAGS ${CMAKE_EXE_LINKER_FLAGS})
set(TO_CMAKE_SOURCE_DIR "\$\{CMAKE_SOURCE_DIR\}")
set(TO_PROJECT_SOURCE_DIR "\$\{PROJECT_SOURCE_DIR\}")
set(TO_INTER_SOURCES "\$\{INTER_SOURCES\}")
set(TO_DINTER_SOURCES "\$\{DINTER_SOURCES\}")
set(TO_INTER_DINTER_LIBRARIES "\$\{INTER_DINTER_LIBRARIES\}")
set(TO_HAVE_MODULES "\$\{HAVE_FFEAD_MODULES_LIB\}")
set(TO_HAVE_FRAMEWORK "\$\{HAVE_FFEAD_FRWRK_LIB\}")
set(TO_INTER_DINTER_INCLUDES "\$\{INTER_DINTER_INCLUDES\}")

if(SRV_ALL)
	CHECK_INCLUDE_FILE("cinatra.hpp" CINATRA_INC)
	set(Boost_USE_STATIC_LIBS ${BUILD_STATIC_LIBS})
	set(Boost_USE_STATIC_RUNTIME ${BUILD_STATIC_LIBS})
	set(Boost_USE_MULTITHREADED ON)
	find_package(Boost REQUIRED COMPONENTS system context thread)
	include_directories(${Boost_INCLUDE_DIRS})
	find_package(PkgConfig REQUIRED)
	pkg_check_modules(JSONCPP jsoncpp)
	if(CMAKE_INC_PATH)
		set(CMAKE_JSONCPP_INC "${CMAKE_INC_PATH}/include/jsoncpp")
	else()
		set(CMAKE_JSONCPP_INC "/usr/local/include/jsoncpp" "/usr/include/jsoncpp")
		if(APPLE)
			set(CMAKE_JSONCPP_INC "/opt/homebrew/include/jsoncpp")
		endif()
	endif()
	FIND_LIBRARY(HAVE_JSONCPP jsoncpp)
	if(NOT HAVE_JSONCPP)
		message(FATAL_ERROR "jsoncpp library not found")
	endif()
	CHECK_INCLUDE_FILE("drogon/drogon.h" DROGON_INC)
	CHECK_INCLUDE_FILE("drogon/orm/DbClient.h" DROGON_ORM_INC)
	CHECK_INCLUDE_FILE("trantor/net/EventLoop.h" TRANTOR_INC)
	FIND_LIBRARY(HAVE_DROGONLIB drogon)
	if(NOT HAVE_DROGONLIB)
		message(FATAL_ERROR "drogon library not found")
	endif()
	FIND_LIBRARY(HAVE_TRANTORLIB trantor)
	if(NOT HAVE_TRANTORLIB)
		message(FATAL_ERROR "trantor library not found")
	endif()
	FIND_LIBRARY(HAVE_NGHTTP2ASIOLIB nghttp2_asio)
	if(NOT HAVE_NGHTTP2ASIOLIB)
		message(FATAL_ERROR "nghttp2_asio library not found")
	endif()
	#CHECK_INCLUDE_FILE("mongols/http_server.hpp" MONGOLS_INC)
	#FIND_LIBRARY(HAVE_MONGOLSLIB mongols)
	#if(NOT HAVE_MONGOLSLIB)
	#	message(FATAL_ERROR "mongols library not found")
	#endif()
	CHECK_INCLUDE_FILE("uv/include/uv11.hpp" UVCPP_INC)
	FIND_LIBRARY(HAVE_UVCPPLIB uv_cpp)
	if(NOT HAVE_UVCPPLIB)
		message(FATAL_ERROR "uv_cpp library not found")
	endif()
	CHECK_INCLUDE_FILE("server/http/http_server.h" CPPSRV_INC)
	FIND_LIBRARY(HAVE_CPPSRV cppserver)
	if(NOT HAVE_CPPSRV)
		message(FATAL_ERROR "cppserver library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVASIO asio)
	if(NOT HAVE_CPPSRVASIO)
		message(FATAL_ERROR "asio library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVCPPCMN cppcommon)
	if(NOT HAVE_CPPSRVCPPCMN)
		message(FATAL_ERROR "cppcommon library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVFMT fmt)
	if(NOT HAVE_CPPSRVFMT)
		message(FATAL_ERROR "fmt library not found")
	endif()
elseif(SRV_EMB)
	set(SRV_EMB 1)
elseif(SRV_CINATRA)
	set(SRV_CINATRA 1)
	CHECK_INCLUDE_FILE("cinatra.hpp" CINATRA_INC)
	set(Boost_USE_STATIC_LIBS ${BUILD_STATIC_LIBS})
	set(Boost_USE_STATIC_RUNTIME ${BUILD_STATIC_LIBS})
	set(Boost_USE_MULTITHREADED ON)
	find_package(Boost REQUIRED COMPONENTS system)
	include_directories(${Boost_INCLUDE_DIRS})
elseif(SRV_LITHIUM)
	set(SRV_LITHIUM 1)
	set(Boost_USE_STATIC_LIBS ${BUILD_STATIC_LIBS})
	set(Boost_USE_STATIC_RUNTIME ${BUILD_STATIC_LIBS})
	set(Boost_USE_MULTITHREADED ON)
	find_package(Boost REQUIRED COMPONENTS context)
	include_directories(${Boost_INCLUDE_DIRS})
elseif(SRV_DROGON)
	set(SRV_DROGON 1)
	find_package(PkgConfig REQUIRED)
	pkg_check_modules(JSONCPP jsoncpp)
	if(CMAKE_INC_PATH)
		set(CMAKE_JSONCPP_INC "${CMAKE_INC_PATH}/include/jsoncpp")
	else()
		set(CMAKE_JSONCPP_INC "/usr/local/include/jsoncpp" "/usr/include/jsoncpp")
		if(APPLE)
			set(CMAKE_JSONCPP_INC "/opt/homebrew/include/jsoncpp")
		endif()
	endif()
	FIND_LIBRARY(HAVE_JSONCPP jsoncpp)
	if(NOT HAVE_JSONCPP)
		message(FATAL_ERROR "jsoncpp library not found")
	endif()
	CHECK_INCLUDE_FILE("drogon/drogon.h" DROGON_INC)
	CHECK_INCLUDE_FILE("drogon/orm/DbClient.h" DROGON_ORM_INC)
	CHECK_INCLUDE_FILE("trantor/net/EventLoop.h" TRANTOR_INC)
	FIND_LIBRARY(HAVE_DROGONLIB drogon)
	if(NOT HAVE_DROGONLIB)
		message(FATAL_ERROR "drogon library not found")
	endif()
	FIND_LIBRARY(HAVE_TRANTORLIB trantor)
	if(NOT HAVE_TRANTORLIB)
		message(FATAL_ERROR "trantor library not found")
	endif()
elseif(SRV_NGHTTP2)
	set(SRV_NGHTTP2 1)
	set(Boost_USE_STATIC_LIBS ${BUILD_STATIC_LIBS})
	set(Boost_USE_STATIC_RUNTIME ${BUILD_STATIC_LIBS})
	set(Boost_USE_MULTITHREADED ON)
	find_package(Boost REQUIRED COMPONENTS thread system)
	include_directories(${Boost_INCLUDE_DIRS})
	FIND_LIBRARY(HAVE_NGHTTP2ASIOLIB nghttp2_asio)
	if(NOT HAVE_NGHTTP2ASIOLIB)
		message(FATAL_ERROR "nghttp2_asio library not found")
	endif()
#elseif(SRV_MONGOLS)
#	set(SRV_MONGOLS 1)
#	CHECK_INCLUDE_FILE("mongols/http_server.hpp" MONGOLS_INC)
#	FIND_LIBRARY(HAVE_MONGOLSLIB mongols)
#	if(NOT HAVE_MONGOLSLIB)
#		message(FATAL_ERROR "mongols library not found")
#	endif()
elseif(SRV_UVCPP)
	set(SRV_UVCPP 1)
	CHECK_INCLUDE_FILE("uv/include/uv11.h" UVCPP_INC)
	FIND_LIBRARY(HAVE_UVCPPLIB uv_cpp)
	if(NOT HAVE_UVCPPLIB)
		message(FATAL_ERROR "uv_cpp library not found")
	endif()
elseif(SRV_CPPSRV)
	set(SRV_CPPSRV 1)
	CHECK_INCLUDE_FILE("server/http/http_server.h" CPPSRV_INC)
	FIND_LIBRARY(HAVE_CPPSRV cppserver)
	if(NOT HAVE_CPPSRV)
		message(FATAL_ERROR "cppserver library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVASIO asio)
	if(NOT HAVE_CPPSRVASIO)
		message(FATAL_ERROR "asio library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVCPPCMN cppcommon)
	if(NOT HAVE_CPPSRVCPPCMN)
		message(FATAL_ERROR "cppcommon library not found")
	endif()
	FIND_LIBRARY(HAVE_CPPSRVFMT fmt)
	if(NOT HAVE_CPPSRVFMT)
		message(FATAL_ERROR "fmt library not found")
	endif()
endif()

configure_file (
  "${PROJECT_SOURCE_DIR}/src/modules/common/AppDefines.h.in.mc"
  "${PROJECT_SOURCE_DIR}/src/modules/common/AppDefines.h"
)
configure_file (
  "${PROJECT_SOURCE_DIR}/rtdcf/CMakeLists.txt.template.in"
  "${PROJECT_SOURCE_DIR}/rtdcf/CMakeLists.txt.template"
)

add_subdirectory(${PROJECT_SOURCE_DIR}/src/modules)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/framework)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
#add_subdirectory(${PROJECT_SOURCE_DIR}/temp)

#Add any web diectories here
add_subdirectory(${PROJECT_SOURCE_DIR}/web/default)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/flexApp)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/oauthApp)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/markers)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/peer-server)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/te-benchmark)
add_subdirectory(${PROJECT_SOURCE_DIR}/web/t1)
if(MOD_SDORM_MONGO)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t2)
endif()
if(MOD_SDORM_SQL)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t3)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t4)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t5)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t6)
	add_subdirectory(${PROJECT_SOURCE_DIR}/web/t7)
endif()

if(MOD_APACHE)
	add_subdirectory(${PROJECT_SOURCE_DIR}/modules/apache_mod_ffeadcpp)
endif()
if(MOD_NGINX)
	add_subdirectory(${PROJECT_SOURCE_DIR}/modules/nginx_mod_ffeadcpp)
endif()

if(SRV_ALL)
	add_executable(ffead-cpp src/server/embedded/CHServer.cpp)
	set_property(TARGET ffead-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp ffead-modules ffead-framework ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
	
	include_directories("${CINATRA_INCLUDES}")
	add_executable(ffead-cpp-cinatra src/server/cinatra/CinatraServer.cpp)
	find_package(Boost 1.65 REQUIRED COMPONENTS system)
	set_property(TARGET ffead-cpp-cinatra PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-cinatra ffead-modules ffead-framework stdc++fs ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
	
	add_executable(ffead-cpp-lithium src/server/lithium/LithiumServer.cpp)
	set_property(TARGET ffead-cpp-lithium PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-lithium ffead-modules ffead-framework boost_context ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
	include_directories("${CMAKE_JSONCPP_INC}")
	
	add_executable(ffead-cpp-drogon src/server/drogon/DrogonServer.cpp)
	set_property(TARGET ffead-cpp-drogon PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-drogon ffead-modules ffead-framework -Wl,--copy-dt-needed-entries ${HAVE_DROGONLIB} ${HAVE_TRANTORLIB} ${HAVE_JSONCPP} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB} brotlidec brotlienc)
	
	if(NOT DEBUG)
		add_executable(ffead-cpp-nghttp2 src/server/nghttp2/Nghttp2Server.cpp)
		find_package(Boost 1.65 REQUIRED COMPONENTS system thread)
		set_property(TARGET ffead-cpp-nghttp2 PROPERTY POSITION_INDEPENDENT_CODE ON)
		target_link_libraries(ffead-cpp-nghttp2 ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_NGHTTP2ASIOLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
	endif()

	#add_executable(ffead-cpp-mongols src/server/mongols/MongolsServer.cpp)
	#set_property(TARGET ffead-cpp-mongols PROPERTY POSITION_INDEPENDENT_CODE ON)
	#target_link_libraries(ffead-cpp-mongols ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_MONGOLSLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})

	add_executable(ffead-cpp-uvcpp src/server/uv-cpp/UvCppServer.cpp)
	set_property(TARGET ffead-cpp-uvcpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-uvcpp ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_UVCPPLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})

	add_executable(ffead-cpp-cppsrv src/server/cppserver/CppServerServer.cpp)
	set_property(TARGET ffead-cpp-cppsrv PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-cppsrv ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_CPPSRV} ${HAVE_CPPSRVASIO} ${HAVE_CPPSRVCPPCMN} ${HAVE_CPPSRVFMT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_EMB)
	add_executable(ffead-cpp src/server/embedded/CHServer.cpp)
	set_property(TARGET ffead-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp ffead-modules ffead-framework ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_CINATRA)
	include_directories("${CINATRA_INCLUDES}")
	add_executable(ffead-cpp src/server/cinatra/CinatraServer.cpp)
	find_package(Boost 1.65 REQUIRED COMPONENTS system)
	set_property(TARGET ffead-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp ffead-modules ffead-framework stdc++fs ${Boost_LIBRARIES} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_LITHIUM)
	add_executable(ffead-cpp src/server/lithium/LithiumServer.cpp)
	set_property(TARGET ffead-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp ffead-modules ffead-framework boost_context ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_DROGON)
	include_directories("${CMAKE_JSONCPP_INC}")
	add_executable(ffead-cpp src/server/drogon/DrogonServer.cpp)
	set_property(TARGET ffead-cpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp ffead-modules ffead-framework -Wl,--copy-dt-needed-entries ${HAVE_DROGONLIB} ${HAVE_TRANTORLIB} ${HAVE_JSONCPP} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB} brotlidec brotlienc)
elseif(SRV_NGHTTP2)
	add_executable(ffead-cpp-nghttp2 src/server/nghttp2/Nghttp2Server.cpp)
	find_package(Boost 1.65 REQUIRED COMPONENTS system thread)
	set_property(TARGET ffead-cpp-nghttp2 PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-nghttp2 ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_NGHTTP2ASIOLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
#elseif(SRV_MONGOLS)
#	add_executable(ffead-cpp-mongols src/server/mongols/MongolsServer.cpp)
#	set_property(TARGET ffead-cpp-mongols PROPERTY POSITION_INDEPENDENT_CODE ON)
#	target_link_libraries(ffead-cpp-mongols ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_MONGOLSLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_UVCPP)
	add_executable(ffead-cpp-uvcpp src/server/uv-cpp/UvCppServer.cpp)
	set_property(TARGET ffead-cpp-uvcpp PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-uvcpp ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_UVCPPLIB} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
elseif(SRV_CPPSRV)
	add_executable(ffead-cpp-cppsrv src/server/cppserver/CppServerServer.cpp)
	set_property(TARGET ffead-cpp-cppsrv PROPERTY POSITION_INDEPENDENT_CODE ON)
	target_link_libraries(ffead-cpp-cppsrv ffead-modules ffead-framework ${Boost_LIBRARIES} ${HAVE_CPPSRV} ${HAVE_CPPSRVASIO} ${HAVE_CPPSRVCPPCMN} ${HAVE_CPPSRVFMT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${HAVE_ONIG_REGEX_LIB} ${HAVE_UUIDLIB} ${HAVE_CURLLIB} ${HAVE_SSLLIB} ${HAVE_REDISLIB} ${HAVE_REDIS_CLUSTERLIB} ${HAVE_MEMCACHEDLIB} ${HAVE_MEMCACHEDUTILLIB} ${HAVE_ODBCLIB} ${HAVE_ELASTICLIB} ${HAVE_MONGOCLIB} ${HAVE_SCYLLALIB} ${HAVE_PUGI_XML_LIB} ${HAVE_BSONLIB} ${HAVE_ZLIB} ${HAVE_CRYPTOLIB})
endif()

MESSAGE( STATUS "CMAKE_REQUIRED_INCLUDES: " ${CMAKE_REQUIRED_INCLUDES} )
MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )
MESSAGE( STATUS "CMAKE_EXE_LINKER_FLAGS: " ${CMAKE_EXE_LINKER_FLAGS} )
MESSAGE( STATUS "CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX} )
MESSAGE( STATUS "BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS} )
MESSAGE( STATUS "BUILD_STATIC_LIBS: " ${BUILD_STATIC_LIBS} )
MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )
MESSAGE( STATUS "DEBUG: " ${DEBUG} )
if(SRV_CINATRA)
	MESSAGE( STATUS "CINATRA_INCLUDES: " ${CINATRA_INCLUDES} )
elseif (SRV_ALL)
	MESSAGE( STATUS "CINATRA_INCLUDES: " ${CINATRA_INCLUDES} )
endif()
#if (APPLE)
#	MESSAGE( STATUS "SSL_LIB: " ${SSL_LIB} )
#	MESSAGE( STATUS "CRYPTO_LIB: " ${CRYPTO_LIB} )
#endif()

file(REMOVE_RECURSE ${PROJECT_NAME}-bin)
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/resources")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/lib")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/public")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/include")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/rtdcf")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/tmp")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/logs")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/tests")
install(DIRECTORY ${PROJECT_SOURCE_DIR}/resources/ DESTINATION ${PROJECT_NAME}-bin/resources)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/public/ DESTINATION ${PROJECT_NAME}-bin/public)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/rtdcf/ DESTINATION ${PROJECT_NAME}-bin/rtdcf)
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/default")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/flexApp")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/oauthApp")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/markers")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/peer-server")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/te-benchmark")
install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/t1")
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/default/ DESTINATION ${PROJECT_NAME}-bin/web/default)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/flexApp/ DESTINATION ${PROJECT_NAME}-bin/web/flexApp)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/oauthApp/ DESTINATION ${PROJECT_NAME}-bin/web/oauthApp)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/markers/ DESTINATION ${PROJECT_NAME}-bin/web/markers)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/peer-server/ DESTINATION ${PROJECT_NAME}-bin/web/peer-server)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/te-benchmark/ DESTINATION ${PROJECT_NAME}-bin/web/te-benchmark)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t1/ DESTINATION ${PROJECT_NAME}-bin/web/t1)
if(MOD_SDORM_MONGO)
	install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/t2")
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t2/ DESTINATION ${PROJECT_NAME}-bin/web/t2)
endif()
if(MOD_SDORM_SQL)
	install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/t4")
	install(DIRECTORY DESTINATION "${PROJECT_NAME}-bin/web/t5")
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t3/ DESTINATION ${PROJECT_NAME}-bin/web/t3)
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t4/ DESTINATION ${PROJECT_NAME}-bin/web/t4)
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t5/ DESTINATION ${PROJECT_NAME}-bin/web/t5)
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t6/ DESTINATION ${PROJECT_NAME}-bin/web/t6)
	install(DIRECTORY ${PROJECT_SOURCE_DIR}/web/t7/ DESTINATION ${PROJECT_NAME}-bin/web/t7)
endif()
install(DIRECTORY ${PROJECT_SOURCE_DIR}/tests/ DESTINATION ${PROJECT_NAME}-bin/tests)
if(CYGWIN OR MINGW)
	if(CYGWIN)
		install(FILES ${PROJECT_BINARY_DIR}/src/modules/cygffead-modules${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/src/framework/cygffead-framework${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/default/cygdefault${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/flexApp/cygflexApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/oauthApp/cygoauthApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/markers/cygmarkers${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/peer-server/cygpeer-server${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/te-benchmark/cygte-benchmark${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t1/cygt1${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/src/modules/libffead-modules${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/src/framework/libffead-framework${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/default/libdefault${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/flexApp/libflexApp${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/oauthApp/liboauthApp${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/markers/libmarkers${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/peer-server/libpeer-server${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/te-benchmark/libte-benchmark${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t1/libt1${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		if(MOD_SDORM_MONGO)
			install(FILES ${PROJECT_BINARY_DIR}/web/t2/cygt2${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t2/libt2${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
		if(MOD_SDORM_SQL)
			install(FILES ${PROJECT_BINARY_DIR}/web/t3/cygt3${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t4/cygt4${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t5/cygt5${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t6/cygt6${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t7/cygt7${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t3/libt3${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t4/libt4${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t5/libt5${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t6/libt6${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t7/libt7${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
	else()
		install(FILES ${PROJECT_BINARY_DIR}/src/modules/libffead-modules${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/src/framework/libffead-framework${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/default/libdefault${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/flexApp/libflexApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/oauthApp/liboauthApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/markers/libmarkers${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/peer-server/libpeer-server${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/te-benchmark/libte-benchmark${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t1/libt1${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		if(MOD_SDORM_MONGO)
			install(FILES ${PROJECT_BINARY_DIR}/web/t2/libt2${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
		if(MOD_SDORM_SQL)
			install(FILES ${PROJECT_BINARY_DIR}/web/t3/libt3${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t4/libt4${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t5/libt5${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t6/libt6${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t7/libt7${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
		install(FILES ${PROJECT_BINARY_DIR}/src/modules/libffead-modules${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/src/framework/libffead-framework${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/default/libdefault${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/flexApp/libflexApp${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/oauthApp/liboauthApp${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/markers/libmarkers${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/peer-server/libpeer-server${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/te-benchmark/libte-benchmark${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t1/libt1${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		if(MOD_SDORM_MONGO)
			install(FILES ${PROJECT_BINARY_DIR}/web/t2/libt2${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
		if(MOD_SDORM_SQL)
			install(FILES ${PROJECT_BINARY_DIR}/web/t3/libt3${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t4/libt4${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t5/libt5${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t6/libt6${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
			install(FILES ${PROJECT_BINARY_DIR}/web/t7/libt7${LIB_EXT}.a DESTINATION ${PROJECT_NAME}-bin/lib)
		endif()
	endif()
	install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp.exe DESTINATION ${PROJECT_NAME}-bin/)
	if(NOT EMSCRIPTEN)
		install(FILES ${PROJECT_BINARY_DIR}/tests/tests.exe DESTINATION ${PROJECT_NAME}-bin/tests/)
	endif()
else()
	if(NOT EMSCRIPTEN)
		install(FILES ${PROJECT_BINARY_DIR}/tests/tests DESTINATION ${PROJECT_NAME}-bin/tests/)
	else()
	install(FILES ${PROJECT_BINARY_DIR}/tests/tests.js DESTINATION ${PROJECT_NAME}-bin/tests/)
	endif()
	install(FILES ${PROJECT_BINARY_DIR}/src/modules/libffead-modules${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/src/framework/libffead-framework${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/default/libdefault${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/flexApp/libflexApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/oauthApp/liboauthApp${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/markers/libmarkers${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/peer-server/libpeer-server${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/te-benchmark/libte-benchmark${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	install(FILES ${PROJECT_BINARY_DIR}/web/t1/libt1${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	if(MOD_SDORM_MONGO)
		install(FILES ${PROJECT_BINARY_DIR}/web/t2/libt2${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	endif()
	if(MOD_SDORM_SQL)
		install(FILES ${PROJECT_BINARY_DIR}/web/t3/libt3${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t4/libt4${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t5/libt5${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t6/libt6${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
		install(FILES ${PROJECT_BINARY_DIR}/web/t7/libt7${LIB_EXT} DESTINATION ${PROJECT_NAME}-bin/lib)
	endif()
	if(SRV_ALL)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-lithium DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-cinatra DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-drogon DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-nghttp2 DESTINATION ${PROJECT_NAME}-bin/)
		#install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-mongols DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-uvcpp DESTINATION ${PROJECT_NAME}-bin/)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-cppsrv DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_EMB)
		if(NOT EMSCRIPTEN)
			install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp DESTINATION ${PROJECT_NAME}-bin/)
		else()
			install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp.js DESTINATION ${PROJECT_NAME}-bin/)
		endif()
	elseif(SRV_CINATRA)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-cinatra DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_LITHIUM)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-lithium DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_DROGON)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-drogon DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_NGHTTP2)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-nghttp2 DESTINATION ${PROJECT_NAME}-bin/)
	#elseif(SRV_MONGOLS)
	#	install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-mongols DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_UVCPP)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-uvcpp DESTINATION ${PROJECT_NAME}-bin/)
	elseif(SRV_CPPSRV)
		install(FILES ${PROJECT_BINARY_DIR}/ffead-cpp-cppsrv DESTINATION ${PROJECT_NAME}-bin/)
	endif()
endif()
install(FILES ${PROJECT_SOURCE_DIR}/script/server_valgrind.sh DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/server_calgrind.sh DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/server.sh DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/server_debug.sh DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/client.pem DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/dparams.pem DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/rootCA.crt DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/rootCA.key DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/server.key DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/server.crt DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/serverchain.pem DESTINATION ${PROJECT_NAME}-bin/)
install(FILES ${PROJECT_SOURCE_DIR}/script/vhost-server.sh DESTINATION ${PROJECT_NAME}-bin/)
